home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap10 / PoorMenu / PoorMenu.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  3.1 KB  |  96 lines

  1. /*-----------------------------------------
  2.    POORMENU.C -- The Poor Person's Menu
  3.                  (c) Charles Petzold, 1998
  4.   -----------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. #define IDM_SYS_ABOUT   1
  9. #define IDM_SYS_HELP    2
  10. #define IDM_SYS_REMOVE  3
  11.  
  12. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  13.  
  14. static TCHAR szAppName[] = TEXT ("PoorMenu") ;
  15.  
  16. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17.                     PSTR szCmdLine, int iCmdShow)
  18. {
  19.      HMENU    hMenu ;
  20.      HWND     hwnd ;
  21.      MSG      msg ;
  22.      WNDCLASS wndclass ;
  23.      
  24.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  25.      wndclass.lpfnWndProc   = WndProc ;
  26.      wndclass.cbClsExtra    = 0 ;
  27.      wndclass.cbWndExtra    = 0 ;
  28.      wndclass.hInstance     = hInstance ;
  29.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  30.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  31.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  32.      wndclass.lpszMenuName  = NULL ;
  33.      wndclass.lpszClassName = szAppName ;
  34.      
  35.      if (!RegisterClass (&wndclass))
  36.      {
  37.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  38.                       szAppName, MB_ICONERROR) ;
  39.           return 0 ;
  40.      }
  41.      
  42.      hwnd = CreateWindow (szAppName, TEXT ("The Poor-Person's Menu"),
  43.                           WS_OVERLAPPEDWINDOW,
  44.                           CW_USEDEFAULT, CW_USEDEFAULT,
  45.                           CW_USEDEFAULT, CW_USEDEFAULT,
  46.                           NULL, NULL, hInstance, NULL) ;
  47.      
  48.      hMenu = GetSystemMenu (hwnd, FALSE) ;
  49.      
  50.      AppendMenu (hMenu, MF_SEPARATOR, 0,           NULL) ;
  51.      AppendMenu (hMenu, MF_STRING, IDM_SYS_ABOUT,  TEXT ("About...")) ;
  52.      AppendMenu (hMenu, MF_STRING, IDM_SYS_HELP,   TEXT ("Help...")) ;
  53.      AppendMenu (hMenu, MF_STRING, IDM_SYS_REMOVE, TEXT ("Remove Additions")) ;
  54.      
  55.      ShowWindow (hwnd, iCmdShow) ;
  56.      UpdateWindow (hwnd) ;
  57.      
  58.      while (GetMessage (&msg, NULL, 0, 0))
  59.      {
  60.           TranslateMessage (&msg) ;
  61.           DispatchMessage (&msg) ;
  62.      }
  63.      return msg.wParam ;
  64. }
  65.  
  66. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  67. {
  68.      switch (message)
  69.      {
  70.      case WM_SYSCOMMAND:
  71.           switch (LOWORD (wParam))
  72.           {
  73.           case IDM_SYS_ABOUT:
  74.                MessageBox (hwnd, TEXT ("A Poor-Person's Menu Program\n")
  75.                                  TEXT ("(c) Charles Petzold, 1998"),
  76.                            szAppName, MB_OK | MB_ICONINFORMATION) ;
  77.                return 0 ;
  78.                
  79.           case IDM_SYS_HELP:
  80.                MessageBox (hwnd, TEXT ("Help not yet implemented!"),
  81.                            szAppName, MB_OK | MB_ICONEXCLAMATION) ;
  82.                return 0 ;
  83.                
  84.           case IDM_SYS_REMOVE:
  85.                GetSystemMenu (hwnd, TRUE) ;
  86.                return 0 ;
  87.           }
  88.           break ;
  89.           
  90.      case WM_DESTROY:
  91.           PostQuitMessage (0) ;
  92.           return 0 ;
  93.      }
  94.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  95. }
  96.